package com.ymatou.iapi.userservice.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.CheckThirdPartyUserNickNameDtoBean;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.CheckThirdPartyUserNickNameDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.mongo.ULC201406Bean;
import com.ymttest.database.mongo.ULC201406Wapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;
/**
*检查用户昵称是否被非当前用户使用接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CheckThirdPartyUserNickNameDto{
	private static CheckThirdPartyUserNickNameDtoBean checkthirdpartyusernicknamedtoBean;
	private static CheckThirdPartyUserNickNameDtoCall checkthirdpartyusernicknamedtoCall;
	private ULC201406Wapper userWapper;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("检查用户昵称是否被非当前用户使用接口");
	}

	@Before
	public void caseUp() throws Exception {
		checkthirdpartyusernicknamedtoBean=new CheckThirdPartyUserNickNameDtoBean();
		checkthirdpartyusernicknamedtoCall=new CheckThirdPartyUserNickNameDtoCall();
		userWapper = new ULC201406Wapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(checkthirdpartyusernicknamedtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckThirdPartyUserNickNameDto_001() {
		Logger.start(false,"用户昵称被非当前用户使用");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			String uname1=cur.getLoginId();
			
			String phone = TestDataManager.getPhoneNum();
			
			checkthirdpartyusernicknamedtoBean.setNickName(uname1);
			checkthirdpartyusernicknamedtoBean.setMobile(phone);
			checkthirdpartyusernicknamedtoCall.setData(checkthirdpartyusernicknamedtoBean);
			checkthirdpartyusernicknamedtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, checkthirdpartyusernicknamedtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyusernicknamedtoCall.getString("Success"), "验证请求是否成功");
			Logger.verifyEquals(ECode.USER_YES, checkthirdpartyusernicknamedtoCall.getString("Result"), "验证已被非当前用户使用");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckThirdPartyUserNickNameDto_002() {
		Logger.start(true,"用户昵称未被非当前用户使用");
		try {
			String uname1=TestDataManager.getRandomUUID().toString();
			String phone =TestDataManager.getPhoneNum();
			
			checkthirdpartyusernicknamedtoBean.setNickName(uname1);
			checkthirdpartyusernicknamedtoBean.setMobile(phone);
			checkthirdpartyusernicknamedtoCall.setData(checkthirdpartyusernicknamedtoBean);
			checkthirdpartyusernicknamedtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, checkthirdpartyusernicknamedtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyusernicknamedtoCall.getString("Success"), "验证请求是否成功");
			Logger.verifyEquals(ECode.USER_NO, checkthirdpartyusernicknamedtoCall.getString("Result"), "验证未被非当前用户使用");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CheckThirdPartyUserNickNameDto_003() {
		Logger.start(false,"未输入用户昵称，失败");
		try {
			checkthirdpartyusernicknamedtoBean.setMobile(TestDataManager.getPhoneNum());
			checkthirdpartyusernicknamedtoCall.setData(checkthirdpartyusernicknamedtoBean);
			checkthirdpartyusernicknamedtoCall.callService();			
			Logger.verifyEquals(ECode.ERROR400, checkthirdpartyusernicknamedtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("false", checkthirdpartyusernicknamedtoCall.getString("Success"), "验证请求是否成功");
			Logger.verifyIsContains("错误的", checkthirdpartyusernicknamedtoCall.getString("LastErrorMessage"), "验证Msg信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	//不输入手机就check loginid
	public void Tc_CheckThirdPartyUserNickNameDto_004() {
		Logger.start(false,"未输入手机，失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			String uname1=cur.getLoginId();
			
			checkthirdpartyusernicknamedtoBean.setNickName(uname1);
			checkthirdpartyusernicknamedtoCall.setData(checkthirdpartyusernicknamedtoBean);
			checkthirdpartyusernicknamedtoCall.callService();			
			Logger.verifyEquals(ECode.ERROR400, checkthirdpartyusernicknamedtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("false", checkthirdpartyusernicknamedtoCall.getString("Success"), "验证请求是否成功");
			Logger.verifyIsContains("错误的", checkthirdpartyusernicknamedtoCall.getString("LastErrorMessage"), "验证Msg信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckThirdPartyUserNickNameDto_005() {
		Logger.start(false,"用户昵称被非当前用户曾用名使用");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			String uname1=cur.getLoginId();
			
			JUserCallService.SetNickName(uid, "thirdnick_"+ TestDataManager.getRandomNum(10));
			
			String phone = TestDataManager.getPhoneNum();
			
			checkthirdpartyusernicknamedtoBean.setNickName(uname1);
			checkthirdpartyusernicknamedtoBean.setMobile(phone);
			checkthirdpartyusernicknamedtoCall.setData(checkthirdpartyusernicknamedtoBean);
			checkthirdpartyusernicknamedtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, checkthirdpartyusernicknamedtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkthirdpartyusernicknamedtoCall.getString("Success"), "验证请求是否成功");
			Logger.verifyEquals(ECode.USER_YES, checkthirdpartyusernicknamedtoCall.getString("Result"), "验证已被非当前用户使用");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}